home *** CD-ROM | disk | FTP | other *** search
/ AMIGA-CD 2 / Amiga-CD - Volume 2.iso / ungepackte_daten / 1994 / 8 / 05 / term-4.0-source.lha / termDial.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-15  |  33.4 KB  |  1,542 lines

  1. /*
  2. **    termDial.c
  3. **
  4. **    The dialing routine as called by the phonebook
  5. **
  6. **    Copyright © 1990-1994 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* Panel gadget IDs. */
  13.  
  14. enum    {    GAD_CALLING=1,GAD_TIME,GAD_NOTE,
  15.         GAD_SKIP,GAD_REMOVE,GAD_ONLINE,GAD_ABORT
  16.     };
  17.  
  18. STATIC VOID __stdargs
  19. PrintBox(struct LayoutHandle *Handle,LONG Box,LONG Line,STRPTR String,...)
  20. {
  21.     UBYTE     LocalBuffer[256];
  22.     va_list     VarArgs;
  23.  
  24.     va_start(VarArgs,String);
  25.     VSPrintf(LocalBuffer,String,VarArgs);
  26.     va_end(VarArgs);
  27.  
  28.     LT_SetAttributes(Handle,Box,LABX_Index,Line,LABX_Text,LocalBuffer,TAG_DONE);
  29. }
  30.  
  31.     /* BuildName(STRPTR Name):
  32.      *
  33.      *    Build a file name from a BBS name and the current date.
  34.      */
  35.  
  36. STATIC VOID __regargs
  37. BuildName(STRPTR Name,STRPTR Date)
  38. {
  39.     if(Date[0])
  40.     {
  41.         WORD    NameLen = strlen(Name),
  42.             DateLen = strlen(Date),
  43.             Delta;
  44.  
  45.         if((Delta = NameLen + 1 + DateLen - 32) > 0)
  46.             Name[NameLen - Delta] = 0;
  47.  
  48.         strcat(Name,"_");
  49.         strcat(Name,Date);
  50.     }
  51. }
  52.  
  53.     /* OpenAutoCaptureFile(STRPTR SomeName):
  54.      *
  55.      *    Open a capture file.
  56.      */
  57.  
  58. STATIC VOID __regargs
  59. OpenAutoCaptureFile(STRPTR SomeName)
  60. {
  61.     UBYTE        SharedBuffer[MAX_FILENAME_LENGTH],
  62.             Name[50],
  63.             Date[20],
  64.             Time[20];
  65.     struct DateTime    DateTime;
  66.  
  67.         /* Get the current time and date. */
  68.  
  69.     DateStamp(&DateTime . dat_Stamp);
  70.  
  71.         /* Prepare for date conversion. */
  72.  
  73.     DateTime . dat_Format    = FORMAT_DOS;
  74.     DateTime . dat_Flags    = 0;
  75.     DateTime . dat_StrDay    = NULL;
  76.     DateTime . dat_StrDate    = Date;
  77.     DateTime . dat_StrTime    = Time;
  78.  
  79.         /* Convert the date. */
  80.  
  81.     if(DateToStr(&DateTime))
  82.     {
  83.             /* Remember the BBS name. */
  84.  
  85.         strcpy(Name,SomeName);
  86.  
  87.             /* Append the creation date if necessary. */
  88.  
  89.         if(Config -> CaptureConfig -> AutoCaptureDate == AUTOCAPTURE_DATE_NAME)
  90.             BuildName(Name,Date);
  91.  
  92.             /* Make it a reasonable name. */
  93.  
  94.         FixName(Name);
  95.  
  96.             /* Get the capture file path. */
  97.  
  98.         strcpy(SharedBuffer,Config -> CaptureConfig -> CapturePath);
  99.  
  100.             /* Try to build a valid file and path name. */
  101.  
  102.         if(AddPart(SharedBuffer,Name,MAX_FILENAME_LENGTH))
  103.         {
  104.                 /* Is the capture file still open? */
  105.  
  106.             if(FileCapture)
  107.             {
  108.                     /* Close the file. */
  109.  
  110.                 BufferClose(FileCapture);
  111.  
  112.                     /* Any data written? */
  113.  
  114.                 if(!GetFileSize(CaptureName))
  115.                     DeleteFile(CaptureName);
  116.                 else
  117.                 {
  118.                     AddProtection(CaptureName,FIBF_EXECUTE);
  119.  
  120.                     if(Config -> MiscConfig -> CreateIcons)
  121.                         AddIcon(CaptureName,FILETYPE_TEXT,TRUE);
  122.                 }
  123.             }
  124.  
  125.                 /* Try to append the new data. */
  126.  
  127.             if(FileCapture = BufferOpen(SharedBuffer,"a"))
  128.             {
  129.                     /* Set the menu checkmark. */
  130.  
  131.                 CheckItem(MEN_CAPTURE_TO_FILE,TRUE);
  132.  
  133.                     /* Remember the current capture file name. */
  134.  
  135.                 strcpy(CaptureName,SharedBuffer);
  136.  
  137.                     /* Add the creation date if necessary. */
  138.  
  139.                 if(Config -> CaptureConfig -> AutoCaptureDate == AUTOCAPTURE_DATE_INCLUDE)
  140.                 {
  141.                     UBYTE DateTimeBuffer[256];
  142.  
  143.                     if(FormatStamp(&DateTime . dat_Stamp,NULL,NULL,DateTimeBuffer,FALSE))
  144.                         BPrintf(FileCapture,LocaleString(MSG_DIALPANEL_FILE_CREATED_TXT),DateTimeBuffer);
  145.                 }
  146.             }
  147.             else
  148.                 CheckItem(MEN_CAPTURE_TO_FILE,FALSE);
  149.  
  150.             ConOutputUpdate();
  151.         }
  152.     }
  153. }
  154.  
  155.     /* Connect(struct PhoneNode *DialNode,STRPTR NumberBuffer):
  156.      *
  157.      *    Perform connect action(s).
  158.      */
  159.  
  160. STATIC VOID __regargs
  161. Connect(struct PhoneNode *DialNode,STRPTR NumberBuffer)
  162. {
  163.     if(DialNode -> Entry)
  164.     {
  165.         UpdateConfig(DialNode -> Entry -> Config,Config);
  166.  
  167.         ConfigChanged = FALSE;
  168.  
  169.         MakeCall(DialNode -> Entry -> Header -> Name,NumberBuffer);
  170.  
  171.         SelectTime(DialNode -> Entry);
  172.  
  173.         ChosenEntry    = DialNode -> Entry;
  174.         WhichUnit    = DT_FIRST_UNIT;
  175.         CurrentPay    = 0;
  176.         SendStartup    = TRUE;
  177.  
  178.         strcpy(Password,DialNode -> Entry -> Header -> Password);
  179.         strcpy(UserName,DialNode -> Entry -> Header -> UserName);
  180.  
  181.         strcpy(CurrentBBSName,DialNode -> Entry -> Header -> Name);
  182.         strcpy(CurrentBBSComment,DialNode -> Entry -> Header -> Comment);
  183.  
  184.         strcpy(CurrentBBSNumber,NumberBuffer);
  185.  
  186.         if(DialNode -> Entry -> Config && DialNode -> Entry -> Config -> ModemConfig)
  187.         {
  188.             OnlinePlus = DialNode -> Entry -> Config -> ModemConfig -> TimeToConnect;
  189.  
  190.             if(DialNode -> Entry -> Config -> ModemConfig -> ConnectLimit > 0 && DialNode -> Entry -> Config -> ModemConfig -> ConnectLimitMacro[0])
  191.             {
  192.                 LimitCount = DialNode -> Entry -> Config -> ModemConfig -> ConnectLimit;
  193.  
  194.                 strcpy(LimitMacro,DialNode -> Entry -> Config -> ModemConfig -> ConnectLimitMacro);
  195.             }
  196.             else
  197.                 LimitCount = -1;
  198.         }
  199.         else
  200.         {
  201.             OnlinePlus = Config -> ModemConfig -> TimeToConnect;
  202.  
  203.             if(Config -> ModemConfig -> ConnectLimit > 0 && Config -> ModemConfig -> ConnectLimitMacro[0])
  204.             {
  205.                 LimitCount = Config -> ModemConfig -> ConnectLimit;
  206.  
  207.                 strcpy(LimitMacro,Config -> ModemConfig -> ConnectLimitMacro);
  208.             }
  209.             else
  210.                 LimitCount = -1;
  211.         }
  212.  
  213.         LogAction(LocaleString(MSG_DIALPANEL_CONNECTED_TO_1_TXT),DialNode -> Entry -> Header -> Name,NumberBuffer);
  214.     }
  215.     else
  216.     {
  217.         OnlinePlus = Config -> ModemConfig -> TimeToConnect;
  218.  
  219.         MakeCall("???",NumberBuffer);
  220.  
  221.         CurrentPay    = 0;
  222.         ChosenEntry    = NULL;
  223.         Password[0]    = 0;
  224.         UserName[0]    = 0;
  225.         SendStartup    = FALSE;
  226.  
  227.         CurrentBBSName[0]    = 0;
  228.         CurrentBBSComment[0]    = 0;
  229.  
  230.         strcpy(CurrentBBSNumber,NumberBuffer);
  231.  
  232.         if(Config -> ModemConfig -> ConnectLimit > 0 && Config -> ModemConfig -> ConnectLimitMacro[0])
  233.         {
  234.             LimitCount = Config -> ModemConfig -> ConnectLimit;
  235.  
  236.             strcpy(LimitMacro,Config -> ModemConfig -> ConnectLimitMacro);
  237.         }
  238.         else
  239.             LimitCount = -1;
  240.  
  241.         LogAction(LocaleString(MSG_DIALPANEL_CONNECTED_TO_2_TXT),NumberBuffer);
  242.     }
  243.  
  244.         /* We are now online. */
  245.  
  246.     Online = TRUE;
  247.  
  248.         /* Open auto-capture file. */
  249.  
  250.     if(Config -> CaptureConfig -> ConnectAutoCapture && Config -> CaptureConfig -> CapturePath[0])
  251.     {
  252.         if(DialNode -> Entry)
  253.             OpenAutoCaptureFile(DialNode -> Entry -> Header -> Name);
  254.         else
  255.             OpenAutoCaptureFile(LocaleString(MSG_DIALPANEL_CAPTURE_NAME_TXT));
  256.     }
  257.  
  258.         /* Remove node from
  259.          * dialing list and
  260.          * perform system
  261.          * setup.
  262.          */
  263.  
  264.     if(DialNode -> Entry)
  265.         RemoveDialNode(DialNode);
  266.  
  267.     Remove(&DialNode -> VanillaNode);
  268.  
  269.     FreeVecPooled(DialNode);
  270.  
  271.     if(PrivateConfig -> MiscConfig -> BackupConfig)
  272.     {
  273.         if(!BackupConfig)
  274.         {
  275.             if(BackupConfig = CreateConfiguration(TRUE))
  276.                 SaveConfig(PrivateConfig,BackupConfig);
  277.         }
  278.     }
  279.  
  280.         /* Make sure that the following
  281.          * setup/initialization will not
  282.          * touch the serial configuration.
  283.          */
  284.  
  285.     memcpy(PrivateConfig -> SerialConfig,Config -> SerialConfig,sizeof(struct SerialSettings));
  286.  
  287.     ConfigSetup();
  288.  
  289.         /* Reset the scanner. */
  290.  
  291.     FlowInit(TRUE);
  292. }
  293.  
  294.     /* DialPanel():
  295.      *
  296.      *    This routine opens a small window in the middle of the
  297.      *    console window and walks down the list of numbers to
  298.      *    dial.
  299.      */
  300.  
  301. BYTE
  302. DialPanel()
  303. {
  304.     struct LayoutHandle    *Handle;
  305.     struct PhoneNode    *DialNode;
  306.     BYTE             Result = FALSE,
  307.                  Record = FALSE;
  308.  
  309.     BlockWindows();
  310.  
  311.     ChosenEntry = NULL;
  312.  
  313.         /* We are dialing. */
  314.  
  315.     Status = STATUS_DIALING;
  316.  
  317.     if(Handle = LT_CreateHandleTags(Window -> WScreen,
  318.         LH_LocaleHook,    &LocaleHook,
  319.     TAG_DONE))
  320.     {
  321.         struct Window *Window;
  322.  
  323.         LT_New(Handle,
  324.             LA_Type,    VERTICAL_KIND,
  325.         TAG_DONE);
  326.         {
  327.             LT_New(Handle,
  328.                 LA_Type,    VERTICAL_KIND,
  329.             TAG_DONE);
  330.             {
  331.                 LT_New(Handle,
  332.                     LA_Type,    VERTICAL_KIND,
  333.                 TAG_DONE);
  334.                 {
  335.                     LT_New(Handle,
  336.                         LA_Type,        BOX_KIND,
  337.                         LA_ID,            GAD_CALLING,
  338.                         LA_Chars,        45,
  339.                         LA_Lines,        4,
  340.                         LABX_ReserveSpace,    TRUE,
  341.                         LABX_FirstLabel,    MSG_DIALPANEL_CALLING_TXT,
  342.                         LABX_LastLabel,        MSG_DIALPANEL_NEXT_TXT,
  343.                     TAG_DONE);
  344.  
  345.                     LT_New(Handle,
  346.                         LA_Type,        BOX_KIND,
  347.                         LA_ID,            GAD_TIME,
  348.                         LA_Chars,        45,
  349.                         LA_Lines,        2,
  350.                         LABX_ReserveSpace,    TRUE,
  351.                         LABX_FirstLabel,    MSG_DIALPANEL_TIMEOUT_TXT,
  352.                         LABX_LastLabel,        MSG_DIALPANEL_ATTEMPT_TXT,
  353.                     TAG_DONE);
  354.  
  355.                     LT_New(Handle,
  356.                         LA_Type,        BOX_KIND,
  357.                         LA_ID,            GAD_NOTE,
  358.                         LA_Chars,        45,
  359.                         LA_Lines,        1,
  360.                         LABX_ReserveSpace,    TRUE,
  361.                         LABX_FirstLabel,    MSG_DIALPANEL_MESSAGE_TXT,
  362.                         LABX_LastLabel,        MSG_DIALPANEL_MESSAGE_TXT,
  363.                     TAG_DONE);
  364.  
  365.                     LT_EndGroup(Handle);
  366.                 }
  367.  
  368.                 LT_New(Handle,
  369.                     LA_Type,    VERTICAL_KIND,
  370.                 TAG_DONE);
  371.                 {
  372.                     LT_New(Handle,
  373.                         LA_Type,        XBAR_KIND,
  374.                     TAG_DONE);
  375.  
  376.                     LT_New(Handle,
  377.                         LA_Type,        CHECKBOX_KIND,
  378.                         LA_LabelID,        MSG_DIALPANEL_RECORD_ON_CONNECTION_TXT,
  379.                         LA_BYTE,        &Record,
  380.                     TAG_DONE);
  381.  
  382.                     LT_EndGroup(Handle);
  383.                 }
  384.  
  385.                 LT_EndGroup(Handle);
  386.             }
  387.  
  388.             LT_New(Handle,
  389.                 LA_Type,VERTICAL_KIND,
  390.             TAG_DONE);
  391.             {
  392.                 LT_New(Handle,
  393.                     LA_Type,    XBAR_KIND,
  394.                     LAXB_FullSize,    TRUE,
  395.                 TAG_DONE);
  396.  
  397.                 LT_EndGroup(Handle);
  398.             }
  399.  
  400.             LT_New(Handle,LA_Type,HORIZONTAL_KIND,
  401.                 LAGR_Spread,    TRUE,
  402.             TAG_DONE);
  403.             {
  404.                 LT_New(Handle,
  405.                     LA_Type,    BUTTON_KIND,
  406.                     LA_LabelID,    MSG_DIALPANEL_SKIP_GAD,
  407.                     LA_ID,        GAD_SKIP,
  408.                     LABT_ExtraFat,    TRUE,
  409.                 TAG_DONE);
  410.  
  411.                 LT_New(Handle,
  412.                     LA_Type,    BUTTON_KIND,
  413.                     LA_LabelID,    MSG_GLOBAL_REMOVE_GAD,
  414.                     LA_ID,        GAD_REMOVE,
  415.                     LABT_ExtraFat,    TRUE,
  416.                 TAG_DONE);
  417.  
  418.                 LT_New(Handle,
  419.                     LA_Type,    BUTTON_KIND,
  420.                     LA_LabelID,    MSG_DIALPANEL_GO_TO_ONLINE_GAD,
  421.                     LA_ID,        GAD_ONLINE,
  422.                     LABT_ReturnKey,    TRUE,
  423.                     LABT_ExtraFat,    TRUE,
  424.                 TAG_DONE);
  425.  
  426.                 LT_New(Handle,
  427.                     LA_Type,    BUTTON_KIND,
  428.                     LA_LabelID,    MSG_GLOBAL_ABORT_GAD,
  429.                     LA_ID,        GAD_ABORT,
  430.                     LABT_ExtraFat,    TRUE,
  431.                 TAG_DONE);
  432.  
  433.                 LT_EndGroup(Handle);
  434.             }
  435.  
  436.             LT_EndGroup(Handle);
  437.         }
  438.  
  439.         if(Window = LT_Layout(Handle,LocaleString(MSG_DIALPANEL_DIALING_TXT),NULL,0,0,IDCMP_CLOSEWINDOW,0,
  440.             LAWN_HelpHook,        &GuideHook,
  441.             WA_DepthGadget,        TRUE,
  442.             WA_CloseGadget,        TRUE,
  443.             WA_DragBar,        TRUE,
  444.             WA_RMBTrap,        TRUE,
  445.             WA_Activate,        TRUE,
  446.         TAG_DONE))
  447.         {
  448.             struct IntuiMessage    *Message;
  449.             BOOLEAN             Done = FALSE;
  450.             ULONG             MsgClass,
  451.                          MsgQualifier;
  452.             UWORD             MsgCode;
  453.             struct Gadget        *MsgGadget;
  454.             LONG             MsgGadgetID;
  455.  
  456.             LONG             RedialDelay = 0,DialTimeout,DialRetries,DialAttempt;
  457.             BYTE             Dialing,RunCount = 0,GotError = FALSE;
  458.  
  459.             UBYTE             SomeBuffer[300],ExitString[80],
  460.                          NumberBuffer[100],    *NextNumber    = NULL,
  461.                          InitBuffer[80],    *NextInit    = NULL,
  462.                          ExitBuffer[80],    *NextExit    = NULL,
  463.                          PrefixBuffer[80],    *NextPrefix    = NULL;
  464.  
  465.             struct SerialSettings     OriginalSerialConfig;
  466.             BOOLEAN             UseHangUp;
  467.  
  468.             LT_ShowWindow(Handle,TRUE);
  469.  
  470.                 /* Remember the original serial settings, so we
  471.                  * can return to them later.
  472.                  */
  473.  
  474.             CopyMem(Config -> SerialConfig,&OriginalSerialConfig,sizeof(struct SerialSettings));
  475.  
  476.             GuideContext(CONTEXT_DIAL);
  477.  
  478.             ExitString[0] = 0;
  479.  
  480.                 /* Make the current one the active one. */
  481.  
  482.             PushWindow(Window);
  483.  
  484.                 /* Make a backup of the current configuration. */
  485.  
  486.             SaveConfig(Config,PrivateConfig);
  487.  
  488.                 /* Don't echo serial output. */
  489.  
  490.             Quiet        = TRUE;
  491.  
  492.                 /* Perform full sequence check. */
  493.  
  494.             FullCheck    = TRUE;
  495.  
  496.                 /* Reset the scanner. */
  497.  
  498.             FlowInit(TRUE);
  499.  
  500.                 /* Reset the number of dial attempts. */
  501.  
  502.             DialAttempt    = 0;
  503.  
  504.                 /* Get the first dial list entry. */
  505.  
  506.             DialNode    = (struct PhoneNode *)DialList -> lh_Head;
  507.  
  508.                 /* The big dialing loop, implemented as a goto -> mark
  509.                  * loop rather than one of those classical while .. do
  510.                  * loops.
  511.                  */
  512.  
  513. Dial:            Dialing        = TRUE;
  514.  
  515.                 /* Reset the sequence scanner, the user may have skipped
  516.                  * the previous dial attempt causing the modem to return
  517.                  * `NO CARRIER'. To prevent the dialer from skipping the
  518.                  * next dial entry as well as the previous we have to
  519.                  * flush any data pending on the serial line.
  520.                  */
  521.  
  522.             HandleSerial();
  523.  
  524.             FlowInit(TRUE);
  525.  
  526.                 /* Now for multiple phone numbers separated
  527.                  * by `|' characters. If `NextNumber' happens
  528.                  * to be zero, we will prepare to extract
  529.                  * the first phone number from the list.
  530.                  * In any other case we will try to obtain
  531.                  * the next number.
  532.                  */
  533.  
  534.             if(NextNumber)
  535.             {
  536.                 NextNumber    = ExtractString(NextNumber,    NumberBuffer,TRUE);
  537.                 NextInit    = ExtractString(NextInit,    InitBuffer,FALSE);
  538.                 NextExit    = ExtractString(NextExit,    ExitBuffer,FALSE);
  539.                 NextPrefix    = ExtractString(NextPrefix,    PrefixBuffer,FALSE);
  540.             }
  541.             else
  542.             {
  543.                 if(DialNode -> Entry)
  544.                 {
  545.                     NextNumber = ExtractString(DialNode -> Entry -> Header -> Number,NumberBuffer,TRUE);
  546.  
  547.                     if(DialNode -> Entry -> Config -> ModemConfig)
  548.                     {
  549.                         NextInit    = ExtractString(DialNode -> Entry -> Config -> ModemConfig -> ModemInit,InitBuffer,FALSE);
  550.                         NextExit    = ExtractString(DialNode -> Entry -> Config -> ModemConfig -> ModemExit,ExitBuffer,FALSE);
  551.                         NextPrefix    = ExtractString(DialNode -> Entry -> Config -> ModemConfig -> DialPrefix,PrefixBuffer,FALSE);
  552.                     }
  553.                     else
  554.                     {
  555.                         NextInit    = ExtractString(Config -> ModemConfig -> ModemInit,InitBuffer,FALSE);
  556.                         NextExit    = ExtractString(Config -> ModemConfig -> ModemExit,ExitBuffer,FALSE);
  557.                         NextPrefix    = ExtractString(Config -> ModemConfig -> DialPrefix,PrefixBuffer,FALSE);
  558.                     }
  559.                 }
  560.                 else
  561.                 {
  562.                     NextNumber    = ExtractString(DialNode -> VanillaNode . ln_Name,NumberBuffer,TRUE);
  563.  
  564.                     NextInit    = ExtractString(Config -> ModemConfig -> ModemInit,InitBuffer,FALSE);
  565.                     NextExit    = ExtractString(Config -> ModemConfig -> ModemExit,ExitBuffer,FALSE);
  566.                     NextPrefix    = ExtractString(Config -> ModemConfig -> DialPrefix,PrefixBuffer,FALSE);
  567.                 }
  568.             }
  569.  
  570.                 /* If DialNode -> Entry is nonzero it has
  571.                  * a configuration attached.
  572.                  */
  573.  
  574.             if(DialNode -> Entry)
  575.             {
  576.                 if(DialNode -> Entry -> Config -> ModemConfig)
  577.                 {
  578.                     DialTimeout    = DialNode -> Entry -> Config -> ModemConfig -> DialTimeout;
  579.                     DialRetries    = DialNode -> Entry -> Config -> ModemConfig -> DialRetries;
  580.                 }
  581.                 else
  582.                 {
  583.                     DialTimeout    = Config -> ModemConfig -> DialTimeout;
  584.                     DialRetries    = Config -> ModemConfig -> DialRetries;
  585.                 }
  586.  
  587.                     /* Send the modem exit string before we
  588.                      * will need to reconfigure the serial
  589.                      * device driver.
  590.                      */
  591.  
  592.                 if(ExitString[0])
  593.                 {
  594.                     PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_SENDING_MODEM_EXIT_COMMAND_TXT));
  595.  
  596.                     FlowInit(TRUE);
  597.  
  598.                     SerialCommand(ExitString);
  599.  
  600.                     WaitTime(1,0);
  601.  
  602.                     HandleSerial();
  603.  
  604.                     if(FlowInfo . Changed && FlowInfo . Error)
  605.                     {
  606.                         PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT));
  607.  
  608.                         GotError = TRUE;
  609.  
  610.                         goto Quit;
  611.                     }
  612.                 }
  613.  
  614.                     /* We will need to change the serial parameters
  615.                      * in order to establish a connection.
  616.                      */
  617.  
  618.                 if(DialNode -> Entry -> Config -> SerialConfig)
  619.                 {
  620.                     if(ReconfigureSerial(Window,DialNode -> Entry -> Config -> SerialConfig) == RECONFIGURE_FAILURE)
  621.                         goto Quit;
  622.                 }
  623.                 else
  624.                 {
  625.                     if(ReconfigureSerial(Window,&OriginalSerialConfig) == RECONFIGURE_FAILURE)
  626.                         goto Quit;
  627.                 }
  628.  
  629.                     /* Send the modem init string. */
  630.  
  631.                 if(InitBuffer[0] && !Done)
  632.                 {
  633.                     PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_SENDING_MODEM_INIT_COMMAND_TXT));
  634.  
  635.                     FlowInit(TRUE);
  636.  
  637.                     SerialCommand(InitBuffer);
  638.  
  639.                     WaitTime(1,0);
  640.  
  641.                     HandleSerial();
  642.  
  643.                     if(FlowInfo . Changed && FlowInfo . Error)
  644.                     {
  645.                         PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT));
  646.  
  647.                         GotError = TRUE;
  648.  
  649.                         goto Quit;
  650.                     }
  651.                 }
  652.  
  653.                     /* Remember the new exit string. */
  654.  
  655.                 strcpy(ExitString,ExitBuffer);
  656.  
  657.                 PrintBox(Handle,GAD_CALLING,0,DialNode -> Entry -> Header -> Name);
  658.  
  659.                 if(DialNode -> Entry -> Header -> Comment[0])
  660.                     PrintBox(Handle,GAD_CALLING,1,DialNode -> Entry -> Header -> Comment);
  661.                 else
  662.                     PrintBox(Handle,GAD_CALLING,1,"-");
  663.  
  664.                 Say(LocaleString(MSG_DIALPANEL_NOW_CALLING_TXT),DialNode -> Entry -> Header -> Name);
  665.  
  666.                 strcpy(SomeBuffer,PrefixBuffer);
  667.  
  668.                 PrintBox(Handle,GAD_CALLING,2,NumberBuffer);
  669.  
  670.                 strcat(SomeBuffer,NumberBuffer);
  671.             }
  672.             else
  673.             {
  674.                 DialTimeout    = Config -> ModemConfig -> DialTimeout;
  675.                 DialRetries    = Config -> ModemConfig -> DialRetries;
  676.  
  677.                     /* Send the modem exit string. */
  678.  
  679.                 if(ExitString[0])
  680.                 {
  681.                     PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_SENDING_MODEM_EXIT_COMMAND_TXT));
  682.  
  683.                     FlowInit(TRUE);
  684.  
  685.                     SerialCommand(ExitBuffer);
  686.  
  687.                     WaitTime(1,0);
  688.  
  689.                     HandleSerial();
  690.  
  691.                     if(FlowInfo . Changed && FlowInfo . Error)
  692.                     {
  693.                         PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT));
  694.  
  695.                         GotError = TRUE;
  696.  
  697.                         goto Quit;
  698.                     }
  699.                 }
  700.  
  701.                     /* Remember the new exit string. */
  702.  
  703.                 strcpy(ExitString,ExitBuffer);
  704.  
  705.                 PrintBox(Handle,GAD_CALLING,0,LocaleString(MSG_GLOBAL_UNKNOWN_TXT));
  706.  
  707.                 PrintBox(Handle,GAD_CALLING,1,"-");
  708.  
  709.                 Say(LocaleString(MSG_DIALPANEL_NOW_CALLING_TXT),NumberBuffer);
  710.  
  711.                 strcpy(SomeBuffer,PrefixBuffer);
  712.  
  713.                 PrintBox(Handle,GAD_CALLING,2,NumberBuffer);
  714.  
  715.                 strcat(SomeBuffer,NumberBuffer);
  716.  
  717.                     /* Send the modem init string. */
  718.  
  719.                 if(InitBuffer[0])
  720.                 {
  721.                     PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_SENDING_MODEM_INIT_COMMAND_TXT));
  722.  
  723.                     FlowInit(TRUE);
  724.  
  725.                     SerialCommand(InitBuffer);
  726.  
  727.                     WaitTime(1,0);
  728.  
  729.                     HandleSerial();
  730.  
  731.                     if(FlowInfo . Changed && FlowInfo . Error)
  732.                     {
  733.                         PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT));
  734.  
  735.                         GotError = TRUE;
  736.  
  737.                         goto Quit;
  738.                     }
  739.                 }
  740.             }
  741.  
  742.             if(NextNumber)
  743.             {
  744.                 if(DialNode -> Entry)
  745.                     PrintBox(Handle,GAD_CALLING,3,DialNode -> Entry -> Header -> Name);
  746.                 else
  747.                     PrintBox(Handle,GAD_CALLING,3,DialNode -> VanillaNode . ln_Name);
  748.             }
  749.             else
  750.             {
  751.                 if(DialNode -> VanillaNode . ln_Succ -> ln_Succ)
  752.                 {
  753.                     if(DialNode -> Entry)
  754.                         PrintBox(Handle,GAD_CALLING,3,((struct PhoneNode *)DialNode -> VanillaNode . ln_Succ) -> Entry -> Header -> Name);
  755.                     else
  756.                         PrintBox(Handle,GAD_CALLING,3,DialNode -> VanillaNode . ln_Succ -> ln_Name);
  757.                 }
  758.                 else
  759.                     PrintBox(Handle,GAD_CALLING,3,"-");
  760.             }
  761.  
  762.             if(DialNode -> Entry)
  763.             {
  764.                 if(DialNode -> Entry -> Config -> ModemConfig)
  765.                     strcat(SomeBuffer,DialNode -> Entry -> Config -> ModemConfig -> DialSuffix);
  766.                 else
  767.                     strcat(SomeBuffer,Config -> ModemConfig -> DialSuffix);
  768.             }
  769.             else
  770.                 strcat(SomeBuffer,Config -> ModemConfig -> DialSuffix);
  771.  
  772.             PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_DIALING_TXT));
  773.  
  774.                 /* Dial the number. */
  775.  
  776.             SerialCommand(SomeBuffer);
  777.  
  778.                 /* Reset the signal. */
  779.  
  780.             SetSignal(NULL,SIG_SKIP | SIG_BREAK);
  781.  
  782.             while(!Done)
  783.             {
  784.                 if(CheckSignal(SIG_BREAK))
  785.                 {
  786.                     PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_ABORTING_TXT));
  787.  
  788.                     if(DialNode -> Entry && DialNode -> Entry -> Config && DialNode -> Entry -> Config -> ModemConfig)
  789.                         UseHangUp = DialNode -> Entry -> Config -> ModemConfig -> AbortHangsUp;
  790.                     else
  791.                         UseHangUp = Config -> ModemConfig -> AbortHangsUp;
  792.  
  793.                     if(UseHangUp)
  794.                         HangUp();
  795.                     else
  796.                     {
  797.                         SerWrite("\r",1);
  798.                         WaitTime(1,0);
  799.                     }
  800.  
  801.                         /* Ignore the response of the modem. */
  802.  
  803.                     HandleSerial();
  804.  
  805.                     FlowInit(TRUE);
  806.  
  807.                     break;
  808.                 }
  809.  
  810.                 if(Dialing)
  811.                 {
  812.                     PrintBox(Handle,GAD_TIME,0,"%2ld:%02ld",DialTimeout / 60,DialTimeout % 60);
  813.  
  814.                     if(DialRetries < 0)
  815.                         PrintBox(Handle,GAD_TIME,1,LocaleString(MSG_DIAL_RETRIES_UNLIMITED_TXT));
  816.                     else
  817.                         PrintBox(Handle,GAD_TIME,1,LocaleString(MSG_DIALPANEL_ATTEMPT_OF_TXT),DialAttempt + 1,DialRetries);
  818.                 }
  819.                 else
  820.                     PrintBox(Handle,GAD_TIME,0,"%2ld:%02ld",RedialDelay / 60,RedialDelay % 60);
  821.  
  822.                 WaitTime(0,MILLION / 2);
  823.  
  824.                     /* The following commands are executed each second */
  825.  
  826.                 if((RunCount++) && !Done)
  827.                 {
  828.                     RunCount = 0;
  829.  
  830.                         /* Are we dialing or waiting? */
  831.  
  832.                     if(Dialing)
  833.                     {
  834.                             /* No chance, the dial timeout
  835.                              * has elapsed and no connection
  836.                              * was made.
  837.                              */
  838.  
  839.                         if(!(--DialTimeout))
  840.                         {
  841.                             PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_DIAL_ATTEMPT_TIMEOUT_TXT));
  842.  
  843. Skip1:
  844.                             if(DialNode -> Entry && DialNode -> Entry -> Config && DialNode -> Entry -> Config -> ModemConfig)
  845.                                 UseHangUp = DialNode -> Entry -> Config -> ModemConfig -> AbortHangsUp;
  846.                             else
  847.                                 UseHangUp = Config -> ModemConfig -> AbortHangsUp;
  848.  
  849.                             if(UseHangUp)
  850.                                 HangUp();
  851.                             else
  852.                             {
  853.                                 SerWrite("\r",1);
  854.                                 WaitTime(1,0);
  855.                             }
  856.  
  857.                                 /* Ignore the response of the modem. */
  858.  
  859.                             HandleSerial();
  860.  
  861.                             FlowInit(TRUE);
  862.  
  863.                                 /* Did we dial all the numbers available? */
  864.  
  865.                             if(NextNumber)
  866.                                 goto Dial;
  867.  
  868.                                 /* Is this one the last entry? */
  869.  
  870.                             if(DialNode -> VanillaNode . ln_Succ -> ln_Succ)
  871.                             {
  872.                                     /* Proceed to the next entry. */
  873.  
  874.                                 DialNode = (struct PhoneNode *)DialNode -> VanillaNode . ln_Succ;
  875.  
  876.                                 goto Dial;
  877.                             }
  878.                             else
  879.                             {
  880.                                     /* Is this one the last dial
  881.                                      * attempt to be made?
  882.                                      */
  883.  
  884.                                 if(++DialAttempt >= DialRetries && DialRetries >= 0)
  885.                                 {
  886.                                     PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_MAXIMUM_NUMBER_OF_DIAL_RETRIES_TXT));
  887.  
  888.                                     WakeUp(Window,SOUND_BELL);
  889.  
  890.                                     WaitTime(2,0);
  891.  
  892.                                     Say(LocaleString(MSG_DIALPANEL_MAXIMUM_NUMBER_OF_DIAL_RETRIES_TXT));
  893.  
  894.                                     Done = TRUE;
  895.                                 }
  896.                                 else
  897.                                 {
  898.                                         /* Get the first list entry. */
  899.  
  900.                                     DialNode = (struct PhoneNode *)DialList -> lh_Head;
  901.  
  902.                                         /* Get the redial delay. */
  903.  
  904.                                     if(DialNode -> Entry)
  905.                                     {
  906.                                         if(DialNode -> Entry -> Config -> ModemConfig)
  907.                                             RedialDelay = 10 * DialNode -> Entry -> Config -> ModemConfig -> RedialDelay;
  908.                                         else
  909.                                             RedialDelay = 10 * Config -> ModemConfig -> RedialDelay;
  910.                                     }
  911.                                     else
  912.                                         RedialDelay = 10 * Config -> ModemConfig -> RedialDelay;
  913.  
  914.                                         /* No redial delay? Restart dialing... */
  915.  
  916.                                     if(!RedialDelay)
  917.                                     {
  918.                                         WaitTime(1,0);
  919.  
  920.                                         goto Dial;
  921.                                     }
  922.                                     else
  923.                                     {
  924.                                             /* Go into redial delay. */
  925.  
  926.                                         PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_REDIAL_DELAY_TXT));
  927.  
  928.                                         Dialing = FALSE;
  929.  
  930.                                         Say(LocaleString(MSG_DIALPANEL_WAITING_TXT));
  931.                                     }
  932.                                 }
  933.                             }
  934.                         }
  935.                     }
  936.                     else
  937.                     {
  938.                         if(!(--RedialDelay))
  939.                         {
  940.                                 /* Get the first list entry. */
  941.  
  942. Skip2:                            DialNode = (struct PhoneNode *)DialList -> lh_Head;
  943.  
  944.                                 /* We are once again dialing. */
  945.  
  946.                             goto Dial;
  947.                         }
  948.                     }
  949.                 }
  950.  
  951.                     /* Handle serial data flow. */
  952.  
  953.                 HandleSerial();
  954.  
  955.                     /* Something has changed in the flow
  956.                      * info structure.
  957.                      */
  958.  
  959.                 if(FlowInfo . Changed)
  960.                 {
  961.                         /* Current number is busy. */
  962.  
  963.                     if(FlowInfo . Busy || (FlowInfo . NoCarrier && Config -> ModemConfig -> NoCarrierIsBusy))
  964.                     {
  965.                         FlowInit(TRUE);
  966.  
  967.                         FlowInfo . Busy        = FALSE;
  968.                         FlowInfo . NoCarrier    = FALSE;
  969.                         FlowInfo . Changed    = FALSE;
  970.  
  971.                         if(Dialing)
  972.                         {
  973.                             PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_LINE_IS_BUSY_TXT));
  974.  
  975.                             Say(LocaleString(MSG_DIALPANEL_LINE_IS_BUSY_TXT));
  976.  
  977.                             WaitTime(1,0);
  978.  
  979.                             goto Skip1;
  980.                         }
  981.                     }
  982.  
  983.                         /* Line does not feature a dialtone. */
  984.  
  985.                     if(FlowInfo . NoDialTone)
  986.                     {
  987.                         FlowInit(TRUE);
  988.  
  989.                         PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_NO_DIALTONE_TXT));
  990.  
  991.                         WakeUp(Window,SOUND_BELL);
  992.  
  993.                         WaitTime(2,0);
  994.  
  995.                         Say(LocaleString(MSG_DIALPANEL_NO_DIALTONE_TXT));
  996.  
  997.                         Done = TRUE;
  998.                     }
  999.  
  1000.                         /* Somebody tries to call us. */
  1001.  
  1002.                     if(FlowInfo . Ring && !Done)
  1003.                     {
  1004.                         FlowInit(TRUE);
  1005.  
  1006.                         PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_GLOBAL_INCOMING_CALL_TXT));
  1007.  
  1008.                         WakeUp(Window,SOUND_RING);
  1009.  
  1010.                         WaitTime(2,0);
  1011.  
  1012.                         Say(LocaleString(MSG_GLOBAL_INCOMING_CALL_TXT));
  1013.  
  1014.                         Done = TRUE;
  1015.                     }
  1016.  
  1017.                         /* Somebody's talking. */
  1018.  
  1019.                     if(FlowInfo . Voice && !Done)
  1020.                     {
  1021.                         FlowInit(TRUE);
  1022.  
  1023.                         PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_INCOMING_VOICE_CALL_TXT));
  1024.  
  1025.                         WakeUp(Window,SOUND_VOICE);
  1026.  
  1027.                         WaitTime(2,0);
  1028.  
  1029.                         Say(LocaleString(MSG_DIALPANEL_INCOMING_VOICE_CALL_TXT));
  1030.  
  1031.                         Done = TRUE;
  1032.                     }
  1033.  
  1034.                         /* We got a connect. */
  1035.  
  1036.                     if(FlowInfo . Connect && !Done)
  1037.                     {
  1038.                         FlowInfo . Connect = FALSE;
  1039.                         FlowInfo . Changed = FALSE;
  1040.  
  1041.                         Connect(DialNode,NumberBuffer);
  1042.  
  1043.                         Done = TRUE;
  1044.  
  1045.                             /* Wake the user up. */
  1046.  
  1047.                         if(BaudBuffer[0])
  1048.                         {
  1049.                             PrintBox(Handle,GAD_NOTE,0,"CONNECT %s",BaudBuffer);
  1050.  
  1051.                             WakeUp(Window,SOUND_CONNECT);
  1052.  
  1053.                             WaitTime(2,0);
  1054.  
  1055.                                 /* Install new baud rate if desired. */
  1056.  
  1057.                             if(Config -> ModemConfig -> ConnectAutoBaud && DTERate > 110)
  1058.                             {
  1059.                                 Config -> SerialConfig -> BaudRate = DTERate;
  1060.  
  1061.                                 ReconfigureSerial(Window,NULL);
  1062.                             }
  1063.                         }
  1064.                         else
  1065.                         {
  1066.                             PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_CONNECTION_ESTABLISHED_TXT));
  1067.  
  1068.                             WakeUp(Window,SOUND_CONNECT);
  1069.                         }
  1070.  
  1071.                         Say(LocaleString(MSG_DIALPANEL_CONNECTION_ESTABLISHED_TXT));
  1072.                     }
  1073.                 }
  1074.  
  1075.                     /* Look for the hotkey. */
  1076.  
  1077.                 if(CheckSignal(SIG_SKIP))
  1078.                 {
  1079.                     LT_PressButton(Handle,GAD_SKIP);
  1080.  
  1081.                         /* Are we dialing or waiting? */
  1082.  
  1083.                     if(Dialing)
  1084.                     {
  1085.                         DialTimeout = 0;
  1086.  
  1087.                         goto Skip1;
  1088.                     }
  1089.                     else
  1090.                     {
  1091.                         RedialDelay = 0;
  1092.  
  1093.                         goto Skip2;
  1094.                     }
  1095.                 }
  1096.  
  1097.                     /* Pick up the window input. */
  1098.  
  1099.                 while(!Done && (Message = (struct IntuiMessage *)GT_GetIMsg(Window -> UserPort)))
  1100.                 {
  1101.                     MsgClass    = Message -> Class;
  1102.                     MsgQualifier    = Message -> Qualifier;
  1103.                     MsgCode        = Message -> Code;
  1104.                     MsgGadget    = (struct Gadget *)Message -> IAddress;
  1105.  
  1106.                     GT_ReplyIMsg(Message);
  1107.  
  1108.                     LT_HandleInput(Handle,MsgQualifier,&MsgClass,&MsgCode,&MsgGadget);
  1109.  
  1110.                     if(MsgClass == IDCMP_GADGETUP)
  1111.                         MsgGadgetID = MsgGadget -> GadgetID;
  1112.  
  1113.                     if(MsgClass == IDCMP_RAWKEY)
  1114.                     {
  1115.                         if(LT_GetCode(MsgQualifier,MsgClass,MsgCode,MsgGadget) == ' ')
  1116.                         {
  1117.                             MsgClass    = IDCMP_GADGETUP;
  1118.                             MsgCode        = 0;
  1119.                             MsgGadgetID    = GAD_SKIP;
  1120.  
  1121.                             LT_PressButton(Handle,GAD_SKIP);
  1122.                         }
  1123.                     }
  1124.  
  1125.                         /* Close the window, hang up the line. */
  1126.  
  1127.                     if(MsgClass == IDCMP_CLOSEWINDOW)
  1128.                     {
  1129.                         MsgClass    = IDCMP_GADGETUP;
  1130.                         MsgGadgetID    = GAD_ABORT;
  1131.  
  1132.                         Result = TRUE;
  1133.                     }
  1134.  
  1135.                     if(MsgClass == IDCMP_GADGETUP)
  1136.                     {
  1137.                         switch(MsgGadgetID)
  1138.                         {
  1139.                                     /* Don't proceed to the next number in the buffer! */
  1140.  
  1141.                             case GAD_REMOVE:
  1142.  
  1143.                                 NextNumber = NULL;
  1144.  
  1145.                                 if(Dialing)
  1146.                                 {
  1147.                                     struct PhoneNode *NextNode = NULL;
  1148.  
  1149.                                         /* Is there another entry in the list? */
  1150.  
  1151.                                     if(DialNode -> VanillaNode . ln_Succ -> ln_Succ)
  1152.                                         NextNode = (struct PhoneNode *)DialNode -> VanillaNode . ln_Succ;
  1153.                                     else
  1154.                                     {
  1155.                                             /* No, there isn't; do we have a list with
  1156.                                              * at least two entries in it?
  1157.                                              */
  1158.  
  1159.                                         if(DialList -> lh_Head -> ln_Succ -> ln_Succ)
  1160.                                         {
  1161.                                                 /* There is just a single entry
  1162.                                                  * available, check for dial retry
  1163.                                                  * limit.
  1164.                                                  */
  1165.  
  1166.                                             if(++DialAttempt >= DialRetries && DialRetries >= 0)
  1167.                                             {
  1168.                                                 PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_MAXIMUM_NUMBER_OF_DIAL_RETRIES_TXT));
  1169.  
  1170.                                                 WakeUp(Window,SOUND_BELL);
  1171.  
  1172.                                                 WaitTime(2,0);
  1173.  
  1174.                                                 Say(LocaleString(MSG_DIALPANEL_MAXIMUM_NUMBER_OF_DIAL_RETRIES_TXT));
  1175.  
  1176.                                                 Done = TRUE;
  1177.                                             }
  1178.                                             else
  1179.                                             {
  1180.                                                     /* Grab first list entry and continue. */
  1181.  
  1182.                                                 NextNode = (struct PhoneNode *)DialList -> lh_Head;
  1183.                                             }
  1184.                                         }
  1185.                                         else
  1186.                                         {
  1187.                                             Done = TRUE;
  1188.  
  1189.                                             PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_DIALING_LIST_IS_EMPTY_TXT));
  1190.  
  1191.                                             WaitTime(2,0);
  1192.                                         }
  1193.                                     }
  1194.  
  1195.                                     DialTimeout = 0;
  1196.  
  1197.                                     if(DialNode -> Entry && DialNode -> Entry -> Config && DialNode -> Entry -> Config -> ModemConfig)
  1198.                                         UseHangUp = DialNode -> Entry -> Config -> ModemConfig -> AbortHangsUp;
  1199.                                     else
  1200.                                         UseHangUp = Config -> ModemConfig -> AbortHangsUp;
  1201.  
  1202.                                     if(UseHangUp)
  1203.                                         HangUp();
  1204.                                     else
  1205.                                     {
  1206.                                         SerWrite("\r",1);
  1207.                                         WaitTime(1,0);
  1208.                                     }
  1209.  
  1210.                                         /* Ignore the response of the modem. */
  1211.  
  1212.                                     HandleSerial();
  1213.  
  1214.                                     FlowInit(TRUE);
  1215.  
  1216.                                         /* Remove dial entry from list. */
  1217.  
  1218.                                     if(DialNode -> Entry)
  1219.                                         RemoveDialNode(DialNode);
  1220.  
  1221.                                     Remove(&DialNode -> VanillaNode);
  1222.  
  1223.                                     FreeVecPooled(DialNode);
  1224.  
  1225.                                         /* Is there an entry to proceed with? */
  1226.  
  1227.                                     if(NextNode)
  1228.                                     {
  1229.                                         DialNode = NextNode;
  1230.  
  1231.                                         goto Dial;
  1232.                                     }
  1233.                                 }
  1234.                                 else
  1235.                                 {
  1236.                                     struct PhoneNode *LastNode;
  1237.  
  1238.                                         /* We are to leave the redial delay loop,
  1239.                                          * are there at least two entries in
  1240.                                          * the list?
  1241.                                          */
  1242.  
  1243.                                     if(!DialList -> lh_Head -> ln_Succ -> ln_Succ)
  1244.                                     {
  1245.                                             /* No, there is just a single entry in
  1246.                                              * the list.
  1247.                                              */
  1248.  
  1249.                                         Done = TRUE;
  1250.  
  1251.                                         PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_DIALING_LIST_IS_EMPTY_TXT));
  1252.  
  1253.                                         if(DialNode -> Entry && DialNode -> Entry -> Config && DialNode -> Entry -> Config -> ModemConfig)
  1254.                                             UseHangUp = DialNode -> Entry -> Config -> ModemConfig -> AbortHangsUp;
  1255.                                         else
  1256.                                             UseHangUp = Config -> ModemConfig -> AbortHangsUp;
  1257.  
  1258.                                         if(UseHangUp)
  1259.                                             HangUp();
  1260.                                         else
  1261.                                         {
  1262.                                             SerWrite("\r",1);
  1263.                                             WaitTime(2,0);
  1264.                                         }
  1265.  
  1266.                                             /* Ignore the response of the modem. */
  1267.  
  1268.                                         HandleSerial();
  1269.  
  1270.                                         FlowInit(TRUE);
  1271.                                     }
  1272.  
  1273.                                         /* Remove last dial entry from list. */
  1274.  
  1275.                                     LastNode = (struct PhoneNode *)DialList -> lh_TailPred;
  1276.  
  1277.                                     if(LastNode -> Entry)
  1278.                                         RemoveDialNode(LastNode);
  1279.  
  1280.                                     Remove(&LastNode -> VanillaNode);
  1281.  
  1282.                                     FreeVecPooled(LastNode);
  1283.  
  1284.                                         /* Get back to first list entry. */
  1285.  
  1286.                                     if(!Done)
  1287.                                     {
  1288.                                         RedialDelay = 0;
  1289.  
  1290.                                         goto Skip2;
  1291.                                     }
  1292.                                 }
  1293.  
  1294.                                 break;
  1295.  
  1296.                             case GAD_SKIP:
  1297.  
  1298.                                 if(Dialing)
  1299.                                 {
  1300.                                     DialTimeout = 0;
  1301.  
  1302.                                     goto Skip1;
  1303.                                 }
  1304.                                 else
  1305.                                 {
  1306.                                     RedialDelay = 0;
  1307.  
  1308.                                     goto Skip2;
  1309.                                 }
  1310.  
  1311.                             case GAD_ONLINE:
  1312.  
  1313.                                 Connect(DialNode,NumberBuffer);
  1314.  
  1315.                                 Done = TRUE;
  1316.  
  1317.                                 break;
  1318.  
  1319.                                 /* Abort the dialing process. */
  1320.  
  1321.                             case GAD_ABORT:
  1322.  
  1323.                                 Done = TRUE;
  1324.  
  1325.                                 PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_ABORTING_TXT));
  1326.  
  1327.                                 if(DialNode -> Entry && DialNode -> Entry -> Config && DialNode -> Entry -> Config -> ModemConfig)
  1328.                                     UseHangUp = DialNode -> Entry -> Config -> ModemConfig -> AbortHangsUp;
  1329.                                 else
  1330.                                     UseHangUp = Config -> ModemConfig -> AbortHangsUp;
  1331.  
  1332.                                 if(UseHangUp)
  1333.                                     HangUp();
  1334.                                 else
  1335.                                 {
  1336.                                     SerWrite("\r",1);
  1337.                                     WaitTime(1,0);
  1338.                                 }
  1339.  
  1340.                                     /* Ignore the response of the modem. */
  1341.  
  1342.                                 HandleSerial();
  1343.  
  1344.                                 FlowInit(TRUE);
  1345.  
  1346.                                 break;
  1347.                         }
  1348.                     }
  1349.                 }
  1350.             }
  1351.  
  1352.                 /* Are we online or not? */
  1353.  
  1354. Quit:            if(!Online)
  1355.             {
  1356.                     /* Is the serial setup different? */
  1357.  
  1358.                 if(memcmp(Config -> SerialConfig,PrivateConfig -> SerialConfig,sizeof(struct SerialSettings)))
  1359.                 {
  1360.                         /* Swap the serial data. */
  1361.  
  1362.                     swmem(Config -> SerialConfig,PrivateConfig -> SerialConfig,sizeof(struct SerialSettings));
  1363.  
  1364.                         /* Set up the old serial configuration. */
  1365.  
  1366.                     if(ReconfigureSerial(Window,NULL) != RECONFIGURE_FAILURE)
  1367.                     {
  1368.                         if(ExitString[0])
  1369.                         {
  1370.                             PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_SENDING_MODEM_EXIT_COMMAND_TXT));
  1371.  
  1372.                             FlowInit(TRUE);
  1373.  
  1374.                             SerialCommand(ExitBuffer);
  1375.  
  1376.                             WaitTime(1,0);
  1377.  
  1378.                             HandleSerial();
  1379.  
  1380.                             if(FlowInfo . Changed && FlowInfo . Error)
  1381.                             {
  1382.                                 PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT));
  1383.  
  1384.                                 GotError = TRUE;
  1385.                             }
  1386.                         }
  1387.  
  1388.                         if(Config -> ModemConfig -> ModemInit[0] && !GotError)
  1389.                         {
  1390.                             PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_SENDING_MODEM_INIT_COMMAND_TXT));
  1391.  
  1392.                             FlowInit(TRUE);
  1393.  
  1394.                             SerialCommand(Config -> ModemConfig -> ModemInit);
  1395.  
  1396.                             WaitTime(1,0);
  1397.  
  1398.                             HandleSerial();
  1399.  
  1400.                             if(FlowInfo . Changed && FlowInfo . Error)
  1401.                             {
  1402.                                 PrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT));
  1403.  
  1404.                                 GotError = TRUE;
  1405.                             }
  1406.                         }
  1407.                     }
  1408.                 }
  1409.             }
  1410.  
  1411.             if(GotError)
  1412.             {
  1413.                 WORD i;
  1414.  
  1415.                 for(i = GAD_SKIP ; i <= GAD_REMOVE ; i++)
  1416.                     LT_SetAttributes(Handle,i,GA_Disabled,TRUE,TAG_DONE);
  1417.  
  1418.                 WakeUp(Window,SOUND_BELL);
  1419.  
  1420.                 Done = FALSE;
  1421.  
  1422.                 do
  1423.                 {
  1424.                     if(Wait(PORTMASK(Window -> UserPort) | SIG_BREAK) & SIG_BREAK)
  1425.                         break;
  1426.  
  1427.                     while(Message = (struct IntuiMessage *)GT_GetIMsg(Window -> UserPort))
  1428.                     {
  1429.                         MsgClass    = Message -> Class;
  1430.                         MsgQualifier    = Message -> Qualifier;
  1431.                         MsgCode        = Message -> Code;
  1432.                         MsgGadget    = (struct Gadget *)Message -> IAddress;
  1433.  
  1434.                         GT_ReplyIMsg(Message);
  1435.  
  1436.                         LT_HandleInput(Handle,MsgQualifier,&MsgClass,&MsgCode,&MsgGadget);
  1437.  
  1438.                         if(MsgClass == IDCMP_CLOSEWINDOW || MsgClass == IDCMP_GADGETUP)
  1439.                             Done = TRUE;
  1440.                     }
  1441.                 }
  1442.                 while(!Done);
  1443.             }
  1444.  
  1445.             PopWindow();
  1446.         }
  1447.  
  1448.         LT_DeleteHandle(Handle);
  1449.     }
  1450.  
  1451.     ReleaseWindows();
  1452.  
  1453.             /* Reset the scanner. */
  1454.  
  1455.     FullCheck = FALSE;
  1456.  
  1457.     FlowInit(TRUE);
  1458.  
  1459.         /* We are done now, restart echoing serial */
  1460.  
  1461.     Quiet = FALSE;
  1462.  
  1463.         /* Reset the display if necessary. */
  1464.  
  1465.     if(ResetDisplay)
  1466.     {
  1467.         if(!DisplayReset())
  1468.             return(FALSE);
  1469.     }
  1470.  
  1471.     if(Online)
  1472.     {
  1473.         SetDialMenu(FALSE);
  1474.  
  1475.             /* Send the startup macro if necessary. */
  1476.  
  1477.         if(SendStartup)
  1478.         {
  1479.             if(Config -> CommandConfig -> LoginMacro[0])
  1480.                 SerialCommand(Config -> CommandConfig -> LoginMacro);
  1481.  
  1482.             if(Config -> CommandConfig -> StartupMacro[0])
  1483.                 SerialCommand(Config -> CommandConfig -> StartupMacro);
  1484.  
  1485.             SendStartup = FALSE;
  1486.         }
  1487.  
  1488.             /* Take care of the recording feature. */
  1489.  
  1490.         if(Record)
  1491.         {
  1492.             if(CreateRecord(CurrentBBSName[0] ? CurrentBBSName : CurrentBBSNumber))
  1493.             {
  1494.                 RememberResetOutput();
  1495.                 RememberResetInput();
  1496.  
  1497.                 RememberOutput = TRUE;
  1498.  
  1499.                 Recording = TRUE;
  1500.                 RecordingLine = FALSE;
  1501.  
  1502.                 OnItem(MEN_RECORD_LINE);
  1503.             
  1504.                 CheckItem(MEN_RECORD,TRUE);
  1505.                 CheckItem(MEN_RECORD_LINE,FALSE);
  1506.             }
  1507.         }
  1508.  
  1509.         Forbid();
  1510.  
  1511.         if(DialMsg)
  1512.         {
  1513.             DialMsg -> rm_Result1 = RC_OK;
  1514.             DialMsg -> rm_Result2 = 0;
  1515.  
  1516.             ReplyMsg(DialMsg);
  1517.  
  1518.             DialMsg = NULL;
  1519.         }
  1520.  
  1521.         Permit();
  1522.     }
  1523.     else
  1524.     {
  1525.         Forbid();
  1526.  
  1527.         if(DialMsg)
  1528.         {
  1529.             DialMsg -> rm_Result1 = RC_WARN;
  1530.             DialMsg -> rm_Result2 = 0;
  1531.  
  1532.             ReplyMsg(DialMsg);
  1533.  
  1534.             DialMsg = NULL;
  1535.         }
  1536.  
  1537.         Permit();
  1538.     }
  1539.  
  1540.     return(Result);
  1541. }
  1542.